/**
 @文件名： layoutInfo
 @来源：YongPing.Wang|2023/11/17 15:25
 @描述：平台框架储存信息
 **/

import { defineStore } from 'pinia'
import baseParam from '@/config/parameter/baseParam.ts'
import { ELangType } from '@/lang/types.ts'
import { EPlatformLayout } from '@/store/types.ts'
import { EPlatformTheme } from '@/theme/types.ts'
import Log from '@/config/common/log.ts'

interface ILayoutInfo {
  localeConfig: ELangType // 国际化
  platformLayout: EPlatformLayout // 平台布局
  platformTheme: EPlatformTheme // 平台主题
  platformMenuOpen: boolean // 平台菜单是否折叠
  platformConfigOpen: boolean // 平台配置页面是否显示
}

export const layoutInfo = defineStore({
  id: `${baseParam.systemDefaultPrefix}_LAYOUT_INFO`,
  state: (): ILayoutInfo => {
    return {
      localeConfig: ELangType.ZHCN,
      platformLayout: EPlatformLayout.leftRightLayout,
      platformTheme: EPlatformTheme.defaultTheme,
      platformMenuOpen: true,
      platformConfigOpen: false,
    }
  },
  actions: {
    // 设置主题
    setPlatformTheme(name: EPlatformTheme): void {
      this.platformTheme = name
    },
    // 设置语言
    setLocaleConfig(name: ELangType): void {
      this.localeConfig = name
    },
    // 设置布局
    setPlatformLayout(name: EPlatformLayout): void {
      this.platformLayout = name
      Log.capsule('设置布局', String(name))
    },
    // 设置菜单收缩展开
    setPlatformMenuOpen(name: boolean): void {
      this.platformMenuOpen = name
    },
    // 设置配置 显示
    setPlatformConfigOpen(name: boolean): void {
      this.platformConfigOpen = name
    },
    // 清空 信息
    removeLayoutInfo() {
      this.$reset()
    },
  },
  persist: true,
})
